import instance from "@/main";
import lineOrderDict from "@/dict/order-line";
import { isSeller } from "@/util/common";

const btns = [
  // 买家同意卖家修改线路订单申请
  {
    name: "同意",
    clickEvent: "buyerAcceptModifyGoodsLine",
    flag: "buyerAcceptModifyGoodsLine"
  },
  // 买家拒绝修改订单申请
  {
    name: "拒绝",
    clickEvent: "buyerRejectModifyGoodsLine",
    flag: "buyerRejectModifyGoodsLine"
  },
  // 买家同意修改线升贴水申请
  {
    name: "同意",
    clickEvent: "buyerAcceptModifyPremiumLine",
    flag: "buyerAcceptModifyPremiumLine"
  },
  // 买家拒绝修改升贴水申请
  {
    name: "拒绝",
    clickEvent: "buyerRejectModifyPremiumLine",
    flag: "buyerRejectModifyPremiumLine"
  },
  // 卖家备注
  {
    name: "备注",
    clickEvent: "sellerRemarkLineOrder",
    flag: "sellerRemarkLineOrder"
  },
  // 买家备注
  {
    name: "备注",
    clickEvent: "buyerRemarkLineOrder",
    flag: "buyerRemarkLineOrder"
  },
  // 修改价格
  // 点价
  {
    name: "同意改价",
    clickEvent: "acceptSellerModifyBasePriceByLine",
    flag: "acceptSellerModifyBasePriceByLine"
  },
  {
    name: "拒绝改价",
    clickEvent: "rejectSellerModifyBasePriceByLine",
    flag: "rejectSellerModifyBasePriceByLine"
  },
  // 确定价
  {
    name: "同意改价",
    clickEvent: "acceptSellerModifyFirmPriceByLine",
    flag: "acceptSellerModifyFirmPriceByLine"
  },
  {
    name: "拒绝改价",
    clickEvent: "rejectSellerModifyFirmPriceByLine",
    flag: "rejectSellerModifyFirmPriceByLine"
  }
];

function btnJudge(flag, row) {
  let res = false;
  // // 是否超管
  // let isSuperAdmin = function() {
  //   return instance.$isSuperAdmin(
  //     instance.$store.state.user.userData &&
  //       instance.$store.state.user.userData.userState
  //   );
  // };
  // // 是否管理员以上
  // let isAdmin = function() {
  //   return instance.$store.state.user.isAdmin;
  // };
  // // 是否点价人
  // let isCreatedUser = function() {
  //   return (
  //     row.userId ===
  //     (instance.$store.state.user.userData &&
  //       instance.$store.state.user.userData.userId)
  //   );
  // };
  switch (flag) {
    // 买家备注订单
    case "buyerRemarkLineOrder":
      res = !isSeller();
      break;
    // 卖家备注订单
    case "sellerRemarkLineOrder":
      res = isSeller();
      break;
    // 买家同意卖家修改线路订单申请
    case "buyerAcceptModifyGoodsLine":
      res =
        !isSeller() &&
        row.auditLineOrder &&
        row.auditLineOrder.lineOrderAuditState ===
          lineOrderDict.auditStatus.modifyGoods.value;
      break;
    // 买家拒绝修改订单申请
    case "buyerRejectModifyGoodsLine":
      res =
        !isSeller() &&
        row.auditLineOrder &&
        row.auditLineOrder.lineOrderAuditState ===
          lineOrderDict.auditStatus.modifyGoods.value;
      break;
    // 买家同意修改线升贴水申请
    case "buyerAcceptModifyPremiumLine":
      res =
        !isSeller() &&
        row.auditLineOrder &&
        row.auditLineOrder.lineOrderAuditState ===
          lineOrderDict.auditStatus.modifyPremium.value;
      break;
    // 买家拒绝修改升贴水申请
    case "buyerRejectModifyPremiumLine":
      res =
        !isSeller() &&
        row.auditLineOrder &&
        row.auditLineOrder.lineOrderAuditState ===
          lineOrderDict.auditStatus.modifyPremium.value;
      break;
    default:
      break;
  }
  return res;
}

let setBtns = function(row) {
  let res = [];
  btns.forEach(item => {
    // 判断是否拥有对应权限、对应的订单状态、是否管理员、当前用户是否点价人、发布人
    if (instance.$verifyBtn(item.flag)) {
      if (btnJudge(item.flag, row)) {
        res.push(item);
      }
    }
  });
  return res;
};

export default setBtns;
